/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author stana
 */
public class Connection
{
    private static Connection instance;
    private java.sql.Connection conn;
    private Statement statement;
    private String databaseFileName;
    private Connection()
    {
        
    }
    
    public void conenctDatabase()
    {
        try
        {
            Class.forName("org.sqlite.JDBC");
            conn = DriverManager.getConnection("jdbc:sqlite:"+databaseFileName);
            statement = conn.createStatement();
        } catch (ClassNotFoundException ex)
        {
            Logger.getLogger(TrainingTable.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex)
        {
            Logger.getLogger(TrainingTable.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void closeConnection() 
    {
        try
        {
            statement.close();
            conn.close();
        } catch (SQLException ex)
        {
            Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public java.sql.Connection getConnection()
    {
        return conn;
    }
    public Statement getStatement()
    {
        return statement;
    }
    public static Connection getInstance()
    {
        if(instance==null)
        {
            instance=new Connection();
        }
        return instance;
    }
    
    public void setDatabaseFileName(String name)
    {
        databaseFileName=name;
    }
}
